package com.example.composemodifiterdemo

import android.annotation.SuppressLint
import android.graphics.BitmapFactory
import android.os.Bundle
import android.view.Menu
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.CutCornerShape
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.Key.Companion.Menu
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

/**
 *@author: njb
 *@date:  2023/2/8 16:53
 *@desc:
 */
class ScaffoldSampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
          scaffoldSample()
        }
    }

    @SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
    @OptIn(ExperimentalMaterial3Api::class)
    @Preview
    @Composable
    fun scaffoldSample() {
        var selectedItem by remember { mutableStateOf(0) }
        val items = listOf(
            Item("主页", R.drawable.home),
            Item("列表", R.drawable.list),
            Item("设置", R.drawable.settings)
        )
        Scaffold(//简单的首页布局
            topBar = {
                TopAppBar(
                    title = {
                        Text(text = items[selectedItem].name)
                    },
                    navigationIcon = {
                        IconButton(onClick = { /*TODO*/ }) {
                            Icon(Icons.Filled.Menu, null)
                        }
                    }
                )

            },
            //添加底部导航栏
            bottomBar = {
                BottomNavigation() {
                    items.forEachIndexed(){ index,item ->
                        BottomNavigationItem(
                            selected = selectedItem == index,
                            onClick = { selectedItem = index },
                        icon = {Icon(painterResource(item.icon),null)},
                        alwaysShowLabel = true,
                        label = { Text(text = item.name)})
                    }
                }
            }
        ) {
            Box(
                modifier = Modifier.fillMaxSize(),
                contentAlignment = Alignment.Center
            ) {
                Text(text = items[selectedItem].name)
            }
        }
    }

    data class Item(
        val name:String,
        val icon:Int
    )


}
